#include "DXCamera.h"
#include "DXEngine.h"
#include <DxErr.h>



void CDXCamera::activateCamera()
{
	activateView();
	activatePerspective();
	activateViewPort();
}

void CDXCamera::activateView()
{
	assert(CDXEngine::getInstance()->getD3DDevice() != NULL);
	D3DXMATRIX mtxView;
	D3DXVECTOR3 cameraPos(m_view.m_vecPos.m_fX, m_view.m_vecPos.m_fY, m_view.m_vecPos.m_fZ);
	D3DXVECTOR3 cameraLookAt(m_view.m_vecLook.m_fX, m_view.m_vecLook.m_fY, m_view.m_vecLook.m_fZ);
	D3DXVECTOR3 upVector(m_view.m_vecUp.m_fX, m_view.m_vecUp.m_fY, m_view.m_vecUp.m_fZ);
	
	D3DXMatrixLookAtLH(	&mtxView,
		&cameraPos, 
		&cameraLookAt, 
		&upVector);
	HR(CDXEngine::getInstance()->getD3DDevice()->SetTransform(D3DTS_VIEW, &mtxView));
}

void CDXCamera::activatePerspective()
{
	D3DXMATRIX mtxProj;

	D3DXMatrixPerspectiveFovLH(	&mtxProj, 
		m_persp.m_fFOV,
		m_persp.m_fAspectRatio,
		m_persp.m_fNearPlaneDist,
		m_persp.m_fFarPlaneDist);
	HR(CDXEngine::getInstance()->getD3DDevice()->SetTransform(D3DTS_PROJECTION, &mtxProj));
}

void CDXCamera::activateViewPort()
{
	D3DVIEWPORT9 vp;

	vp.X = m_viewPort.m_uiX;
	vp.Y = m_viewPort.m_uiY;
	vp.Width = m_viewPort.m_uiWidth;
	vp.Height = m_viewPort.m_uiHeight;
	vp.MinZ = m_viewPort.m_fMinZ;
	vp.MaxZ = m_viewPort.m_fMaxZ;
	HR(CDXEngine::getInstance()->getD3DDevice()->SetViewport(&vp));
}